package com.hhkj.admin.train.common.mybatis.handler;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONWriter;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.hhkj.admin.train.domain.TrainQuestionOption;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;

import java.util.List;


/**
 * TrainQuestionListHandler
 *
 * @author ByChen
 * @since 2023/05/24
 */
@Slf4j
@MappedJdbcTypes(JdbcType.VARCHAR)
public class TrainQuestionOptionListHandler extends AbstractJsonTypeHandler<List<TrainQuestionOption>> {
    @Override
    protected List<TrainQuestionOption> parse(String json) {
        return JSONArray.parseArray(json, TrainQuestionOption.class);
    }

    @Override
    protected String toJson(List<TrainQuestionOption> obj) {
        return JSONArray.toJSONString(obj,
                JSONWriter.Feature.WriteNullListAsEmpty,
                JSONWriter.Feature.WriteMapNullValue,
                JSONWriter.Feature.WriteNullStringAsEmpty
        );
    }
}
